//引入样式
require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("../../assets/fonts/iconfont.css");
require("./index.less");

//引入模块
const dom = require("../../utils/dom.js");
require("../../libs/swiper/swiper-bundle.css");
const Swiper = require("../../libs/swiper/swiper-bundle.js");
const { default: axios } = require("axios");

document.addEventListener("DOMContentLoaded", function () {
	var mySwiper = new Swiper(".swiper", {
		loop: true, // 循环模式选项
		autoplay: {
			delay: 1000,
			stopOnLastSlide: false,
			disableOnInteraction: false, //用户滑动之后不禁用
		},
		// 如果需要分页器
		pagination: {
			el: ".swiper-pagination",
		},
	});

	//渲染排名
	axios.defaults.baseURL = "http://fitness.h5.itsource.cn:3701";
	axios.defaults.headers.common["Authorization"] =
		"Bearer " + localStorage.getItem("token");
	axios.get("/api/user/info").then((res) => {
		dom.get("#rankNum").textContent = res.data.data.ranking;
		dom.get("#clocinNum").textContent = res.data.data.clockCount;
		dom.get("#resultNum").textContent = res.data.data.badges;
    
	});
	//是否打卡
	function clock() {
		axios.get("/api/user/clockInInfo").then((res) => {
			if (res.data.data.isClockIn) {
				dom.get("#clokinbtn").style.disabled = true;
				dom.get("#clokinbtn").style.background = "#ccc";
				dom.get("#clokinbtn").textContent = "今日已打卡";
			}
		});
	}
	clock();
  //打卡点击事件
	dom.get("#clokinbtn").addEventListener("click", function () {
		axios.post("/api/user/clockIn").then((res) => {
			console.log(res);
			if (res.data.errno === -1) {
				alert("明天再来,今天已打卡");
				clock();
			}
		});
	});

  //累计运动徽章
  

});
